<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="ygy_repairProject"
      :isSelectColumn="false"
      :columns="columns"
      :dataSource="list"
      height="auto"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { queryChargeDifferentiationList } from '@/api/repair/repairReception/repairBusinessManger';
import { getAllUser } from '@/api/customerRepair/activityVisit/resultEntry'; // 查询所有用户
import moment from 'moment';
import { getAllRepairPart } from '@/api/repair/repairManage/repairQuery';
import { getNameByIds } from '@/api/repair/common/index.js';

export default {
  name: 'repairProject',
  mixins: [dictionary],
  props: {
    roPartsProject: {
      type: Array,
      default: () => []
    },
  },
  data() {
    return {
      columns: this.createTable(),
      list: [],
      roParts:{},
      tableData: []
    };
  },
  created() {
    let roNo = this.roNo;
    this.queryAdditionaItem();
  },
  mounted() {
    // this.columns.find(item => item.dataIndex === 'sender').dictItems = this.allUser;
    // this.columns.find(item => item.dataIndex === 'receiver').dictItems = this.allUser;
    this.$refs.table.SET_TABLE_DATA(this.roPartsProject);
    this.columns.find(x => x.dataIndex === 'chargePartitionCode').dictItems = this.chargePartition;
  },
  methods: {
    // 获取所有的人员
    async getNameByIds(parmas) {
      let res = await getNameByIds(parmas);
      if (res.resultCode == 200) {
        let userList = res.data.map(x => ({ text: x.employeeName, value: x.employeeId + '' }));
        this.columns.find(x => x.dataIndex === 'sender').dictItems = userList;
        this.columns.find(x => x.dataIndex === 'receiver').dictItems = userList;
      }
    },
    dealerTranslate() {
      let userIds = [];
      this.tableData.forEach(item => {
        item.sender && userIds.push(item.sender);
        item.receiver && userIds.push(item.receiver);
      });
      if (!userIds.length) return;
      let newUserIds = Array.from(new Set(userIds)); // 数组去重
      let userIdsStr = newUserIds.join(',');
      if (!userIdsStr.length) return;
      this.getNameByIds({ userIds: userIdsStr });
    },
    async queryAdditionaItem() {
      console.log(JSON.stringify(this.roPartsProject)+"-------------roPartsProject--------roPartsProject-----------------")
      // const roNo = this.roNo;
      // const res = (await addItem(roNo)).data.rows;
      // this.list = res;
    },
    tableChangeFun(data) {
      this.tableData = data;
      console.log("+++++++++++++++++++++++this.tableData维修材料"+JSON.stringify(this.tableData))
      this.dealerTranslate();
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费区分',
          dataIndex: 'accountTypeName',
          sorter: true,
          dictItems: []
        },

        {
          title: '仓库代码',
          dataIndex: 'storageCode',
          sorter: true
        },
        {
          title: '备件代码',
          dataIndex: 'partNo',
          sorter: true
        },
        {
          title: '备件名称',
          dataIndex: 'partName',
          sorter: true
        },
        {
          title: '是否主要备件',
          dataIndex: 'isMainPart',
          sorter: true,
          dictItems: this.createDictList('1004')
        },
        {
          title: '备件数量',
          dataIndex: 'partQuantity',
          sorter: true,
          precision: 2
        },
        {
          title: '计量单位',
          dataIndex: 'unitName',
          sorter: true,
          precision: 2
        },
        {
          title: '备件销售单价',
          dataIndex: 'partSalesPrice',
          sorter: true,
          initialValue: '0',
          precision: 2
        },
        {
          title: '备件销售金额',
          dataIndex: 'partSalesAmount',
          sorter: true,
          precision: 2
        },
        // {
        //   title: '配件成本单价',
        //   dataIndex: 'partCostPrice',
        //   summationPrecision: 2,
        //   sorter: true
        // },
        // {
        //   title: '配件成本金额',
        //   dataIndex: 'partCostAmount',
        //   sorter: true
        // },
        // {
        //   title: '优惠金额',
        //   dataIndex: 'preferentialAmount',
        //   sorter: true,
        //   precision: 2
        // },
        // {
        //   title: '折扣率',
        //   dataIndex: 'discount',
        //   sorter: true
        // },
        {
          title: '实收金额',
          dataIndex: 'realAmount',
          sorter: true,
          precision: 2
        },
        // {
        //   title: '是否入账',
        //   dataIndex: 'isFinished',
        //   sorter: true,
        //   render: props => {
        //     return <span>{this.createDictText(props.row.isFinished, '1004')}</span>;
        //   }
        // },
        // {
        //   title: '发料人',
        //   dataIndex: 'sender',
        //   sorter: true,
        //   dictItems: []
        // },
        // {
        //   title: '是否增项',
        //   dataIndex: 'isAddition',
        //   sorter: true,
        //   render: props => {
        //     // return <span>{this.createDictText(props.row.IS_ADDITION, '1004')}</span>;
        //     return <el-checkbox checked={props.row.isAddition == 10041001} disabled></el-checkbox>;
        //   }
        // },
        // {
        //   title: '领料人',
        //   dataIndex: 'receiver',
        //   sorter: true,
        //   dictItems: []
        // },
        // {
        //   title: '是否不修',
        //   dataIndex: 'needlessRepair',
        //   sorter: true,
        //   editable: false,
        //   render: props => {
        //     return <span>{this.createDictText(props.row.needlessRepair, '1004')}</span>;
        //   }
        // },
        // {
        //   title: '不修原因',
        //   dataIndex: 'needlessReason'
        // },
        {
          title: '维修项目代码',
          dataIndex: 'labourCode',
          sorter: true
        },
        {
          title: '活动代码',
          dataIndex: 'activityCode',
          sorter: true
        }
      ];
    }
  }
};
</script>

<style lang="less"></style>
